#!/usr/bin/env python
# coding: utf-8

import web
import options

db = web.database(dbn='mysql', db='feed', user='root', pw='yunlian', host='127.0.0.1')

def getVisit():
    return 4
    #visit = db.select('sys', what='value', where='`sid` =1' , limit=1)
    #return visit[0]['value']

def getTableSize():
    size = db.query('SHOW TABLE STATUS LIKE \'post_into\'')
    return size[0]['Data_length']

def strip_tags(html):
    result = []
    parser = HTMLParser()
    parser.handle_data = result.append
    parser.feed(html)
    parser.close()
    return ''.join(result)

#render = web.template.render('templates', globals={'stat':status})

def formatSize(ss, u = 'B', p = 1):
    us['B']='K'
    us['K']='M'
    us['M']='G'
    us['G']='T'
    #s,$u='B',$p=1)
    #return (($u!=='B')&&(!isset($us[$u]))||($s<1024))?(number_format($s,$p)." $u"):(formatSize($s/1024,$us[$u],$p));
    #return ((u !== 'B') && )

s = getTableSize()
print s

render = web.template.render('templates/', cache=False)
visit = getVisit()

web.config.debug = True

config = web.storage(
    email = 'wangtao@iwangtao.com',
    site_name = '我的订阅',
    site_url = 'http://localhost:8080',
    site_desc = '',
    static = '/static',
    visit = visit,
)

web.template.Template.globals['config'] = config
web.template.Template.globals['render'] = render
web.template.Template.globals['stripTags'] = strip_tags

